/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.treepoke.util.file;

import java.io.File;
import java.util.TimerTask;

/**
 * 
 * @author http://www.rgagnon.com/javadetails/java-0490.html
 */
public abstract class FileWatcher extends TimerTask {

    private long timeStamp;
    private File file;

    public FileWatcher(File file) {
        this.file = file;
        this.timeStamp = file.lastModified();
    }

    public final void run() {
        long timeStampTmp = file.lastModified();

        if (this.timeStamp != timeStampTmp) {
            this.timeStamp = timeStampTmp;
            onChange(file);
        }
    }

    protected abstract void onChange(File file);
}